<template>
    <div class="home">
      <el-container>
        <!--          导航栏-->
        <el-header>
          <div class="home_container">
            <div class="home_wrapper">
              <div><img src="../assets/logo.png"></div>
              <div>电商后台管理系统</div>
            </div>
            <div><el-button type="info" round size="small" @click="onclickout">退出登录</el-button></div>
          </div>
        </el-header>

        <el-container>
          <!--        侧边栏-->
          <el-aside width="200px">
            <el-menu background-color="rgb(45,60,65)"
                     text-color="#fff"
                     :default-openeds="openeds"
                     :default-active="'0-0'"
                     @select="onselect">
              <el-submenu v-for="(item,index) in menulist"
                          :key="index"
                          :index="String(index)">
                <template slot="title">
                  <i :class="item.icon">
                  </i>{{item.menutile}}
                </template>
                <el-menu-item v-for="(menuitem,menuindex) in item.subMenus"
                              :index="`${index}-${menuindex}`">
                              {{menuitem.subMenuName}}
                </el-menu-item>
              </el-submenu>
            </el-menu>
          </el-aside>
    <!--   中间内容-->
          <el-main>
            <router-view/><!--  坑-->
          </el-main>
        </el-container>
      </el-container>
    </div>
</template>

<script>
    export default {
      data(){
        return{
          menulist:[],
          openeds:[0]
        }
      },
      mounted() {
        this.$axios.get('http://localhost:8080/menulist.json').then(res=>{
          this.menulist=res.data
          // console.log((this.menulist))
        })
      },
      methods:{
        onclickout(){ //退出登录
          localStorage.removeItem('token')  //删除本地保存
          this.$router.push({path:'/login'})  //并跳转到登录页
        },
        onselect(index,indexPath){  //导航路由切换
          var path=''
            switch (index) {
              case "0-0":
                path='/'
                break;
              case "1-0":
                path='/jurisdiction'
                break;
              case "1-1":
                path='/role'
                break
            }
            this.$router.push(path)
        }
      }
    }
</script>

<style scoped>
  .el-header, .el-footer {
    background-color: rgb(45,60,65);
    width: 100%;
    height: 60px;
  }

  .el-aside {
    background-color: rgb(45,60,65);
    color: white;
    text-align: center;
    line-height: 200px;
    height: 90vh;
  }

  .el-main {
    background-color: #E9EEF3;
    color: #333;

  }

  body > .el-container {
    margin-bottom: 40px;
  }

  .el-container:nth-child(5) .el-aside,
  .el-container:nth-child(6) .el-aside {
    line-height: 260px;
  }

  .el-container:nth-child(7) .el-aside {
    line-height: 320px;
  }

  .home_container{
    width: 100%;
    height: 100%;
    display: inline-flex;
    justify-content: space-between;
    align-items: center;
  }

  .home_wrapper{
    display: inline-flex;
    justify-content: center;
    align-items: center;
    color: white;
    font-size: 30px;
    font-weight: 700;
  }

  .home_wrapper div{
    display: inline-flex;
    justify-content: center;
    align-items: center;

  }

  .home_wrapper img {
    width: 50px;
    height: 100%;
  }
</style>